package com.demo.controller;


import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("openai")
public class OpenAiChatController {
    private final OpenAiChatModel chatModel;
    // 注入OpenAiChatModel
    public OpenAiChatController(OpenAiChatModel chatModel) {
        this.chatModel = chatModel;
    }
    @GetMapping("/chat")
    public String chat(@RequestParam String message) {
        // 直接调用模型
        return chatModel.call(message);
    }
}
